package com.hs.server;

import com.hs.grpc.CarViewType;
import com.hs.grpc.CheckAppearanceRequest;
import com.hs.server.service.JianyanHsService;
import com.hs.server.service.impl.JianyanHsServiceImpl;
import io.grpc.StatusRuntimeException;

import java.util.Arrays;

public class GrpcTest {
    public static void main(String[] args) {
        //初始化资源信息
        JianyanHsService jianyanService = new JianyanHsServiceImpl("172.16.30.86", 9090);
        CheckAppearanceRequest checkAppearanceRequest = CheckAppearanceRequest.newBuilder()
        .setPlateAnswer("粤S0G06D")//车辆车牌答案
        .setBrandAnswer("东风牌")//车辆品牌答案
        .setColorAnswer("E")//车辆颜色答案（E：红色）换成其它颜色不通过
        .setViewType("0112".equals("0111") ? CarViewType.FRONTLEFT : CarViewType.BACKRIGHT)
        .addAllItems(Arrays.asList("jy_001_001,jy_001_002".split(",")))
        .setVehicleThreshold(1)//车辆阈值
        .setColsData(1.5f)
        .setRowsData(1.5f)
        //.setVehicleLicenseImg(ByteString.copyFrom(ConvertUtil.urlTobyte("http://192.168.1.225:8060/Home/getDetVehPicture?lsh=440012220114000730003&zpzl=0256")))
        .setSourceImage("http://172.16.30.115:8099/240329440002N0003950_0111.jpg").build();
        String btgjyx = "";
        try {
            btgjyx = jianyanService.CheckAppearance("jy_001_001,jy_001_002", checkAppearanceRequest);
        }catch (StatusRuntimeException e){
            e.printStackTrace();
            System.out.println("我异常了！");
        }
        System.out.println("不通过检验项："+btgjyx);
        //ManagedChannel  channel = jianyanService.initResource("192.168.224.202", 50051);
        //
//        CheckIdentificationCardRequest request = CheckIdentificationCardRequest.newBuilder()
//                .setSourceImage(ByteString.copyFrom(ConvertUtil.urlTobyte("http://172.16.30.115:8099/240329440002N0003950_0111.jpg")))
//                //.setIdCardNameAnswer(vehZnshinfo.getSyr())
//                //.setIdCardNumberAnswer()
//                .setCurrentDate(new SimpleDateFormat("yyyy-MM-dd").format(new Date()))
//                .addAllItems(Arrays.asList("jy_029_001".split(","))).build();
//        String btgjyx = jianyanService.CheckIdentificationCard("jy_029_001", request);
//        System.out.println("不通过检验项："+btgjyx);
        //摩托车
        /*CheckMotorAppearanceRequest request = CheckMotorAppearanceRequest.newBuilder()
                .setImg(ByteString.copyFrom(ConvertUtil.urlTobyte("http://192.168.1.119/0111.jpg")))
                //.setArchivalImg(ByteString.copyFrom(ConvertUtil.urlTobyte("http://192.168.1.35/24_0111_JE748T_L9STB5119B1800738_M21_[%E5%A4%B4%E7%9B%94-%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8],[%E8%BD%A6%E7%89%8C%E5%8F%B7-%E4%B8%8E%E5%AE%9E%E9%99%85%E5%80%BC%E6%AF%94%E5%AF%B9].jpg")))
                .setMotorDirection("0111".equals("0111") ? CarViewType.FRONTLEFT : CarViewType.BACKRIGHT)
                .setPlateAnswer("J692TP")
                .setMotorLogoAnswer("五羊")
                .setMotorColorAnswer("E")
                .addAllItems(Arrays.asList("jy_080_001,jy_080_002,jy_080_003,jy_080_004,jy_080_005")).build();
        String btgjyx = jianyanService.CheckMotorAppearance("jy_080_001,jy_080_002,jy_080_003,jy_080_004,jy_080_005",request);
        System.out.println("不通过检验项："+btgjyx);*/

/*        CheckMotorLightRequest request = CheckMotorLightRequest.newBuilder()
                .setPlateAnswer("J915J9")
                .setSourceImage(ByteString.copyFrom(ConvertUtil.urlTobyte("http://192.168.1.119/0352.jpg")))
                .addAllItems(Arrays.asList("jy_082_001,jy_082_002".split(","))).build();
        String btgjyx = jianyanService.CheckMotorLights("jy_082_001,jy_082_002", request);
        System.out.println("不通过检验项："+btgjyx);*/

/*        CheckMotorBrakeRequest request = CheckMotorBrakeRequest.newBuilder()
                .setBrakeType(1)
                .setPlateAnswer("JZ2Q22")
                .setSourceImage(ByteString.copyFrom(ConvertUtil.urlTobyte("http://192.168.1.35/32_0344_JZ2Q22_LC6TCJDF8H0000585_M21_[%E8%BD%A6%E7%89%8C%E5%8F%B7%E7%A0%81-%E4%B8%8E%E5%AE%9E%E9%99%85%E5%80%BC%E6%AF%94%E5%AF%B9].jpg")))
                .setColorAnswer("E")
                .addAllItems(Arrays.asList("jy_085_001,jy_085_002,jy_085_003,jy_085_004".split(","))).build();
        String btgjyx = "";
        btgjyx = jianyanService.CheckMotorBrake("jy_085_001,jy_085_002,jy_085_003,jy_085_004", request);
        System.out.println("不通过检验项："+btgjyx);*/

/*        CheckMotorChassisDynamicsRequest request = CheckMotorChassisDynamicsRequest.newBuilder()
                .setPlateAnswer("J692TP")
                .setSourceImage(ByteString.copyFrom(ConvertUtil.urlTobyte("http://192.168.1.119/0342.jpg")))
                .addAllItems(Arrays.asList("jy_083_001".split(","))).build();
        String btgjyx = jianyanService.CheckMotorChassisDynamics("jy_083_001", request);
        System.out.println("不通过检验项："+btgjyx);*/
        //左前方45度-0111(通过，车辆品牌答案一直返true)
/*        CheckAppearanceRequest checkAppearanceRequest = CheckAppearanceRequest.newBuilder()
                .setPlateAnswer("J97L72")//车辆车牌答案
                .setBrandAnswer("东风牌")//车辆品牌答案
                .setColorAnswer("E")//车辆颜色答案（E：红色）换成其它颜色不通过
                .setViewType("0112".equals("0111") ? CarViewType.FRONTLEFT : CarViewType.BACKRIGHT)
                .addAllItems(Arrays.asList("jy_002_001,jy_002_002,jy_002_005,jy_002_003".split(",")))
                .setVehicleThreshold(1)//车辆阈值
                .setColsData(1.5f)
                .setRowsData(1.5f)
                //.setVehicleLicenseImg(ByteString.copyFrom(ConvertUtil.urlTobyte("http://192.168.1.225:8060/Home/getDetVehPicture?lsh=440012220114000730003&zpzl=0256")))
                .setSourceImage(ByteString.copyFrom(ConvertUtil.urlTobyte("http://192.168.1.186/0112.png"))).build();
        String btgjyx = "";
        try {
            btgjyx = jianyanService.CheckAppearance("jy_002_001,jy_002_002,jy_002_005,jy_002_003", checkAppearanceRequest);
        }catch (StatusRuntimeException e){
            e.printStackTrace();
            System.out.println("我异常了！");
        }
        System.out.println("不通过检验项："+btgjyx);*/

        //车架号-0113(通过)
/*        CheckVinRequest checkVinRequest = CheckVinRequest.newBuilder()
                .setVinAnswer("WDDFH3DB8BJ680202")//识别出来：DD7H3DB3B3624202
                .setVinImg(ByteString.copyFrom(ConvertUtil.urlTobyte("http://192.168.1.225:8060/Home/getDetVehPicture?lsh=440012220114000890001&zpzl=0113")))
                .addAllItems(Arrays.asList("jy_003_001".split(","))).build();
        String btgjyx = jianyanService.CheckVin("jy_003_001","WDDFH3DB8BJ680202", checkVinRequest);
        System.out.println("不通过检验项："+btgjyx);*/

        //安全带-0157（通过）
/*        CheckSeatBeltRequest checkSeatBeltRequest = CheckSeatBeltRequest.newBuilder()
                .setSourceImage(ByteString.copyFrom(ConvertUtil.urlTobyte("http://192.168.1.186/0157.png")))
                .setVehicleThreshold(1)//车辆阈值
                .setColsData(1.5f)
                .setRowsData(1.5f)
                .addAllItems(Arrays.asList("jy_004_001".split(","))).build();
        String btgjyx = jianyanService.CheckSeatBelt("jy_004_001",checkSeatBeltRequest);
        System.out.println("不通过检验项："+btgjyx);*/

        //行驶证-0201(通过,但行驶证 证芯(条形码)编号、发证日期答案数据库为空，默认为空则该两项通过)
/*        CheckVehicleLicenseRequest request = CheckVehicleLicenseRequest.newBuilder()
                .setVinAnswer("LFMAY86C9H0063801")
                .setPlateAnswer("J5K855")
                .setLicenseAnswer("")//4060723772
                .setIssueDateAnswer("")//20160205
                .setSourceImage(ByteString.copyFrom(ConvertUtil.urlTobyte("http://192.168.1.186/jm/0E.jpg")))
                .addAllItems(Arrays.asList("jy_005_001,jy_005_002,jy_005_003,jy_005_004,jy_032_001,jy_051_001".split(","))).build();
        String btgjyx = jianyanService.CheckVehicleLicense("jy_005_001,jy_005_002,jy_005_003,jy_005_004,jy_032_001,jy_051_001", request);
        System.out.println("不通过检验项："+btgjyx);*/
/*        CheckBusinessLicenseRequest request = CheckBusinessLicenseRequest.newBuilder()
                .setSourceImage(ByteString.copyFrom(ConvertUtil.urlTobyte("http://192.168.7.65:6666/Home/getDetVehPicture?lsh=22081644100400014&jyjgbh=4418000004&zpzl=0201")))
                .addAllItems(Arrays.asList("jy_051_001".split(","))).build();
        String btgjyx = jianyanService.CheckBusinessLicense("jy_051_001",request);
        System.out.println("不通过检验项："+btgjyx);*/

        //todo 行驶证背面-0256、行驶证背面2-0224()
/*        CheckVehicleLicenseBackRequest request = CheckVehicleLicenseBackRequest.newBuilder()
                .setSourceImage(ByteString.copyFrom(ConvertUtil.urlTobyte("http://192.168.1.186/0298.png")))
                .setVehicleLicenseColorAnswer("I")//车身颜色答案
                .setVehicleLicenseLogoAnswer("东风牌")//车标答案
                .addAllItems(Arrays.asList("jy_031_001".split(","))).build();
        String btgjyx = jianyanService.CheckVehicleLicenseBack("jy_031_001",request);
        System.out.println("不通过检验项："+btgjyx);*/

        //机动车牌证申请表-0202(通过)
/*        CheckLicenseApplicationFormRequest request = CheckLicenseApplicationFormRequest.newBuilder()
                .setPlateAnswer("粤J97L72")
                .setSourceImage(ByteString.copyFrom(ConvertUtil.urlTobyte("http://192.168.1.186/0202.png")))
                .addAllItems(Arrays.asList("jy_006_001,jy_006_002,jy_006_003,jy_006_004,jy_006_005".split(","))).build();
        String btgjyx = jianyanService.CheckLicenseApplicationForm("jy_006_001,jy_006_002,jy_006_003,jy_006_004,jy_006_005","粤J",request);
        System.out.println("不通过检验项："+btgjyx);*/
        //todo 交强险保单-0203
/*        CheckInsurancePolicyRequest request = CheckInsurancePolicyRequest.newBuilder()
                .setPlateAnswer("粤J3731P".substring(1))
                .setEngineNumberAnswer("A2A17024549")
                .setVinAnswer("LJ13KBBD4J1910471")
                .setStartDate("2023-06-03")
                .setEndDate("2024-06-03")
                .setCurrentDate("2023-07-11")
                .setSourceImage(ByteString.copyFrom(ConvertUtil.urlTobyte("http://192.168.1.186/0203.png")))
                .addAllItems(Arrays.asList("jy_007_001,jy_007_002,jy_007_003,jy_007_004,jy_007_005,jy_007_006,jy_007_007,jy_007_008".split(","))).build();
        String btgjyx = jianyanService.CheckInsurancePolicy("jy_007_001,jy_007_002,jy_007_003,jy_007_004,jy_007_005,jy_007_006,jy_007_007,jy_007_008", request);
        System.out.println("不通过检验项："+btgjyx);*/
        //机动车安全技术检验报告-0204（通过）
/*        CheckInspectionReportRequest request = CheckInspectionReportRequest.newBuilder()
                .setPlateAnswer("J97L72")
                .setVinAnswer("LZWDBAGA4JE636566")
                .setSourceImage(ByteString.copyFrom(ConvertUtil.urlTobyte("http://192.168.1.186/0204.png")))
                .addAllItems(Arrays.asList("jy_008_001,jy_008_002,jy_008_003,jy_008_004,jy_008_005".split(","))).build();
        String btgjyx = jianyanService.CheckInspectionReport("jy_008_001,jy_008_002,jy_008_003,jy_008_004,jy_008_005", request);
        System.out.println("不通过检验项："+btgjyx);*/

        //todo 尾气单1-0295
        //todo 尾气单2-0296
/*        CheckExhaustDetectionReportRequest request = CheckExhaustDetectionReportRequest.newBuilder()
                .setSourceImage1(ByteString.copyFrom(ConvertUtil.urlTobyte("http://192.168.1.186/0297.png")))
                .setSourceImage2(ByteString.copyFrom(ConvertUtil.urlTobyte("http://192.168.1.186/0295.png")))
                .setPlateAnswer("粤B9MU40".substring(1))
                .setVinAnswer("LBVCU3103DSH00901")
                .addAllItems(Arrays.asList("jy_010_001,jy_010_003,jy_010_002,jy_010_005,jy_010_004,jy_010_006".split(","))).build();
        String btgjyx = jianyanService.CheckExhaustDetectionReport("jy_010_001,jy_010_003,jy_010_002,jy_010_005,jy_010_004,jy_010_006", request);
        System.out.println("不通过检验项："+btgjyx);*/
        //委托书-0208（(grpc无返回{})）
/*        CheckAttorneyLetterRequest request = CheckAttorneyLetterRequest.newBuilder()
                .setSourceImage(ByteString.copyFrom(ConvertUtil.urlTobyte("http://192.168.1.225:8060/Home/getDetVehPicture?lsh=440012220114000880001&zpzl=0208")))
                .setVinAnswer("LVGDA46AXAG091323")
                .setPlateNumberAnswer("AZ771G")
                .addAllItems(Arrays.asList("jy_020_001,jy_020_002,jy_020_003".split(","))).build();
        String btgjyx = jianyanService.CheckAttorneyLetter("jy_020_001,jy_020_002,jy_020_003", request);
        System.out.println("不通过检验项："+btgjyx);*/

        //todo 检验表(人工部分)-0212 0213
/*        CheckInspectionFormManualRequest request = CheckInspectionFormManualRequest.newBuilder()
                .setSourceImage(ByteString.copyFrom(ConvertUtil.urlTobyte("http://192.168.1.186/0205.png")))
                //.setSecondImage(ByteString.copyFrom(ConvertUtil.urlTobyte("http://192.168.7.65:6666/Home/getDetVehPicture?lsh=22091544104300001&jyjgbh=4418000043&zpzl=0213")))
                .addAllItems(Arrays.asList("jy_021_001,jy_021_002,jy_021_003,jy_021_004".split(","))).build();
        String btgjyx = jianyanService.CheckInspectionFormManual("jy_021_001,jy_021_002,jy_021_003,jy_021_004",request);
        System.out.println("不通过检验项："+btgjyx);*/
        //todo 检验表仪器部分-0261

        //todo 身份证-A202


        //右灯光-0352
/*        CheckVecicleLightsRequest request = CheckVecicleLightsRequest.newBuilder()
                .setPlateAnswer("J915Z9")
                .setSourceImage(ByteString.copyFrom(ConvertUtil.urlTobyte("http://192.168.1.119/0352.jpg")))
                .setColorAnswer("B")//真实答案B
                .addAllItems(Arrays.asList("jy_012_004,jy_012_005,jy_012_002,jy_012_003,jy_012_001".split(","))).build();
        String btgjyx = jianyanService.CheckVecicleLights("jy_012_004,jy_012_005,jy_012_002,jy_012_003,jy_012_001","JWY156",request);
        System.out.println("不通过检验项："+btgjyx);*/

        //一轴、二轴（平板制动）-0322、 一轴、二轴（滚筒制动）-0348、驻车制动-0351
/*        CheckVecicleBrakeRequest request = CheckVecicleBrakeRequest.newBuilder()
                .setBrakeType(2)
                .setPlateAnswer("JP7745")
                .setSourceImage(ByteString.copyFrom(ConvertUtil.urlTobyte("http://192.168.1.186/jm/%E4%BA%8C%E8%BD%B4%E5%88%B6%E5%8A%A804.jpeg")))
                .setColorAnswer("E")
                .addAllItems(Arrays.asList("jy_015_001,jy_015_002,jy_015_003,jy_015_005".split(","))).build();
        String btgjyx = jianyanService.CheckVecicleBrake("jy_015_001,jy_015_002,jy_015_003,jy_015_005", request);
        System.out.println("不通过检验项："+btgjyx);*/

        //todo 底盘部件（地沟, 年限>10年）-0323(通过，缺少检测日期是否符合要求)
/*        CheckChassisInspectionRequest request = CheckChassisInspectionRequest.newBuilder()
                .setPlateAnswer("JKA234")
                .setSourceImage(ByteString.copyFrom(ConvertUtil.urlTobyte("http://192.168.1.186/jm/%E5%9C%B0%E7%9B%9802.jpeg")))
                .addAllItems(Arrays.asList("jy_019_001,jy_019_002,jy_019_003,jy_019_004".split(","))).build();
        String btgjyx = jianyanService.CheckChassisInspection("jy_019_001,jy_019_002,jy_019_003,jy_019_004", request);
        System.out.println("不通过检验项："+btgjyx);*/
        //todo 底盘动态开始（年限>10年）-0344(通过，缺少检测日期是否符合要求)
/*        CheckChassisDynamicsRequest request = CheckChassisDynamicsRequest.newBuilder()
                .setPlateAnswer("J915Z9")
                .setSourceBeginImage(ByteString.copyFrom(ConvertUtil.urlTobyte("http://192.168.1.119/0344.jpg")))
                .addAllItems(Arrays.asList("jy_016_001,jy_016_002".split(","))).build();
        String btgjyx = jianyanService.CheckChassisDynamics("jy_016_001,jy_016_002", request);
        System.out.println("不通过检验项："+btgjyx);*/
        //todo 底盘动态结束（年限>10年）-0342(通过，缺少检测日期是否符合要求)
/*        CheckChassisDynamicsRequest request = CheckChassisDynamicsRequest.newBuilder()
                .setPlateAnswer("J57581")
                .setSourceEndImage(ByteString.copyFrom(ConvertUtil.urlTobyte("http://192.168.1.186/jm/%E5%8A%A8%E6%80%81%E7%BB%93%E6%9D%9F01.jpeg")))
                .addAllItems(Arrays.asList("jy_017_001,jy_017_002".split(","))).build();
        String btgjyx = jianyanService.CheckChassisDynamics("jy_017_001,jy_017_002", request);
        System.out.println("不通过检验项："+btgjyx);*/
        //todo 车辆后背箱(改装气罐)-0162

        //todo 灭火器-0116

        //todo 安全锤-0117

        //todo 行驶记录装置-0118

        //todo 辅助制动装置-0130

        //todo 防抱死制动装置-0134(通过)
/*        CheckAntilockBrakeSystemRequest request = CheckAntilockBrakeSystemRequest.newBuilder()
                .setSourceImage(ByteString.copyFrom(ConvertUtil.urlTobyte("http://192.168.1.225:8060/Home/getDetVehPicture?lsh=440012220114000180001&zpzl=0134")))
                .addAllItems(Arrays.asList("jy_049_001".split(","))).build();
        String btgjyx = jianyanService.CheckAntilockBrakeSystem("jy_049_001",request);
        System.out.println("不通过检验项："+btgjyx);*/

        //轮胎规格-0136(通过)
/*        CheckTyreSpecificationRequest request = CheckTyreSpecificationRequest.newBuilder()
                .setSourceImage(ByteString.copyFrom(ConvertUtil.urlTobyte("http://192.168.1.225:8060/Home/getDetVehPicture?lsh=440012220114000790001&zpzl=0136")))
                .setTyreSpecificationAnswer("215/65R16")//轮胎规格答案
                .addAllItems(Arrays.asList("jy_040_001".split(","))).build();
        String btgjyx = jianyanService.CheckTyreSpecification("jy_040_001",request);
        System.out.println("不通过检验项："+btgjyx);*/

        //CompletableFuture.runAsync()//流式异步调用


    }
}
